package com.zjuee.web.ledger.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zjuee.base.model.common.ledger.LedgerDisposeGather;
import com.zjuee.base.model.common.ledger.LedgerProduceGather;
import com.zjuee.service.LedgerService;
import com.zjuee.web.ledger.mapper.LedgerDisposeGatherMapper;
import com.zjuee.web.ledger.mapper.LedgerProduceGatherMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author wu liang
 * @since 1.0
 */
@Slf4j
@Service
public class LedgerServiceImpl implements LedgerService {

    @Resource
    private LedgerDisposeGatherMapper ledgerDisposeGatherMapper;

    @Resource
    private LedgerProduceGatherMapper ledgerProduceGatherMapper;

    @Override
    public Boolean selectByGather(Long planId) {
        LambdaQueryWrapper<LedgerDisposeGather> disposeQueryWrapper = Wrappers.<LedgerDisposeGather>query().lambda();
        disposeQueryWrapper.eq(LedgerDisposeGather::getWpiId,planId);
        Integer disposeCount = ledgerDisposeGatherMapper.selectCount(disposeQueryWrapper);
        LambdaQueryWrapper<LedgerProduceGather> produceQueryWrapper = Wrappers.<LedgerProduceGather>query().lambda();
        produceQueryWrapper.eq(LedgerProduceGather::getWpiId,planId);
        Integer produceCount = ledgerProduceGatherMapper.selectCount(produceQueryWrapper);
        return disposeCount > 0 || produceCount > 0;
    }
}
